package com.yanqu.road.server.cmd.activity.ghost;

import com.yanqu.road.pb.activity.GhostActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ghost.GhostModule;
import com.yanqu.road.server.manger.activity.ghost.GhostMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_GHOST_ATTACK_BOSS_FROM_CROSS, desc = "跨服攻击boss返回")
public class GhostAttackBossFromCrossCmd extends AbstractCommand {

    int patronsId;
    String cost;
    int attackTimes;
    long realDamage;
    GhostActivityProto.GhostBossDataMsg bossDataMsg;
    boolean kill;
    String stageReward;
    long userResetTime;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        GhostActivityProto.CrossAttackBossRespMsg reqMsg = GhostActivityProto.CrossAttackBossRespMsg.parseFrom(packet.getBytes());
        ret = reqMsg.getRet();
        patronsId = reqMsg.getPatronsId();
        cost = reqMsg.getCost();
        attackTimes = reqMsg.getAttackTimes();
        userResetTime = reqMsg.getUserResetTime();
        if (ret == 0) {
            realDamage = reqMsg.getRealDamage();
            bossDataMsg = reqMsg.getBossData();
            kill = reqMsg.getIsKill();
            stageReward = reqMsg.getStageReward();
        }
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        GhostMgr.checkUserData(player);

        ret = player.getModule(GhostModule.class).attackBossFromCross(ret, patronsId, cost, attackTimes, realDamage,
                bossDataMsg, kill, stageReward, userResetTime);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            GhostActivityProto.AttackBossRespMsg.Builder builder = GhostActivityProto.AttackBossRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_GHOST_ATTACK_BOSS, builder);
        }
    }
}
